home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Presentations / Presentations ’88 / doco / xmodem by ward. c. < prev   
Text File  |  1987-04-21  |  8KB  |  184 lines

  1. 1002
  2.  
  3.  
  4.  
  5.  
  6. Type P to Pause, S to Stop listing
  7.  
  8. Date Posted: 25 May 1984
  9.  
  10. The following was downloaded from the ACCESS area on CompuServe:
  11.  
  12.  
  13.  
  14. MODEM PROTOCOL OVERVIEW  178 lines, 7.5K
  15.  
  16. 1/1/82 by Ward Christensen.  I will maintain a master copy of this.  Please
  17. pass on changes or suggestions via CBBS/Chicago at (312) 545-8086, or by voice
  18. at (312) 849-6279.
  19.  
  20. NOTE this does not include things which I am not familiar with, such as the CRC
  21. option implemented by John Mahr.
  22.  
  23. Last Rev: (none)
  24.  
  25. At the request of Rick Mallinak on behalf of the guys at Standard Oil with IBM
  26. P.C.s, as well as several previous requests, I finally decided to put my modem
  27. protocol into writing.  It had been previously formally published only in the 
  28. AMRAD newsletter.
  29.  
  30. .   Table of Contents
  31. 1. DEFINITIONS
  32. 2. TRANSMISSION MEDIUM LEVEL PROTOCOL
  33. 3. MESSAGE BLOCK LEVEL PROTOCOL
  34. 4. FILE LEVEL PROTOCOL
  35. 5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY
  36. 6. PROGRAMMING TIPS.
  37.  
  38. -------- 1. DEFINITIONS.
  39. <soh>   01H
  40. <eot>   04H
  41. <ack>   05H
  42. <nak>   15H
  43. <can>   18H
  44.  
  45. -------- 2. TRANSMISSION MEDIUM LEVEL PROTOCOL Asynchronous, 8 data bits, no
  46. parity, one stop bit.
  47.  
  48. .   The protocol imposes no restrictions on the contents of the data being
  49. transmitted.  No control characters are looked for in the 128-byte data
  50. messages.  Absolutely any kind of data may be sent - binary, ASCII, etc.  The
  51. protocol has not formally been adopted to a 7-bit environment for the
  52. transmission of ASCII-only (or unpacked-hex) data , although it could be simply
  53. by having both ends agree to AND the protocol-dependent data with 7F hex before
  54. validating it.  I specifically am referring to the checksum, and the block
  55. numbers and their ones-
  56. complement.
  57. .   Those wishing to maintain compatibility of the CP/M file structure, i.e. to
  58. allow modemming ASCII files to or from CP/M systems should follow this data
  59. format:
  60. . * ASCII tabs used (09H); tabs set every 8.
  61. . * Lines terminated by CR/LF (0DH 0AH)
  62. . * End-of-file indicated by ^Z, 1AH.  (one or more)
  63. . * Data is variable length, i.e. should be considered a
  64. .   continuous stream of data bytes, broken into 128-byte
  65. .   chunks purely for the purpose of transmission. 
  66. . * A CP/M "peculiarity": If the data ends exactly on a
  67. .   128-byte boundary, i.e. CR in 127, and LF in 128, a
  68. .   subsequent sector containing the ^Z EOF character(s)
  69. .   is optional, but is preferred.  Some utilities or
  70. .   user programs still do not handle EOF without ^Zs.
  71. . * The last block sent is no different from others, i.e.
  72. .   there is no "short block".  
  73.  
  74. -------- 3. MESSAGE BLOCK LEVEL PROTOCOL
  75. .Each block of the transfer looks like:
  76. <SOH><blk #><255-blk #><--128 data bytes--><cksum>
  77. .   in which:
  78. <SOH>       = 01 hex
  79. <blk #>     = binary number, starts at 01 increments by 1, and
  80. .             wraps 0FFH to 00H (not to 01)
  81. <255-blk #> = blk # after going thru 8080 "CMA" instr, i.e.
  82. .             each bit complemented in the 8-bit block number.
  83. .             Formally, this is the "ones complement".
  84. <cksum>     = the sum of the data bytes only.  Toss any carry.
  85.  
  86. -------- 4. FILE LEVEL PROTOCOL
  87.  
  88. ---- 4A. COMMON TO BOTH SENDER AND RECEIVER:
  89.  
  90. .   All errors are retried 10 times.  For versions running with an operator
  91. (i.e. NOT with XMODEM), a message is typed after 10 errors asking the operator
  92. whether to "retry or quit".
  93. .   Some versions of the protocol use <can>, ASCII ^X, to cancel transmission. 
  94. This was never adopted as a standard, as having a single "abort" character
  95. makes the transmission susceptible to false termination due to an <ack> <nak>
  96. or <soh>
  97. being corrupted into a <can> and canceling transmission.
  98. .   The protocol may be considered "receiver driven", that is, the sender need
  99. not automatically re-transmit, although it does in the current implementations.
  100.  
  101. ---- 4B. RECEIVE PROGRAM CONSIDERATIONS:
  102. .   The receiver has a 10-second timeout.  It sends a <nak>
  103. every time it times out.  The receiver's first timeout, which sends a <nak>,
  104. signals the transmitter to start.  Optionally, the receiver could send a <nak>
  105. immediately, in case the sender was ready.  This would save the initial 10
  106. second timeout.  However, the receiver MUST continue to timeout every 10
  107. seconds in case the sender wasn't ready.
  108. .   Once into a receiving a block, the receiver goes into a one-second timeout
  109. for each character and the checksum.  If the receiver wishes to <nak> a block
  110. for any reason (invalid header, timeout receiving data), it must wait for the
  111. line to clear.  See "programming tips" for ideas
  112. .   Synchronizing:  If a valid block number is received, it will be: 1) the
  113. expected one, in which case everything is fine;
  114. or 2) a repeat of the previously received block.  This should be considered OK,
  115. and only indicates that the receivers <ack>
  116. got glitched, and the sender re-transmitted; 3) any other block number
  117. indicates a fatal loss of synchronization, such as the rare case of the sender
  118. getting a line-glitch that looked like an <ack>.  Abort the transmission,
  119. sending a <can>
  120.  
  121. ---- 4C. SENDING PROGRAM CONSIDERATIONS.
  122.  
  123. .   While waiting for transmission to begin, the sender has only a single very
  124. long timeout, say one minute.  In the current protocol, the sender has a 10
  125. second timeout before retrying.  I suggest NOT doing this, and letting the
  126. protocol be completely receiver-driven.  This will be compatible with existing
  127. programs.
  128. .   When the sender has no more data, it sends an <eot>, and awaits an <ack>,
  129. resending the <eot> if it doesn't get one.  Again, the protocol could be
  130. receiver-driven, with the sender only having the high-level 1-minute timeout to
  131. abort.
  132.  
  133.  
  134. -------- 5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY
  135.  
  136. Here is a sample of the data flow, sending a 3-block message. It includes the
  137. two most common line hits - a garbaged block, and an <ack> reply getting
  138. garbaged.  <xx> represents the checksum byte.
  139.  
  140. SENDER                  RECEIVER
  141. .               times out after 10 seconds,
  142. .           <---        <nak>
  143. <soh> 01 FE -data- <xx> --->
  144. .           <---        <ack>
  145. <soh> 02 FD -data- xx   --->    (data gets line hit)
  146. .           <---        <nak>
  147. <soh> 02 FD -data- xx   --->
  148. .           <---        <ack>
  149. <soh> 03 FC -data- xx   --->
  150. .  (ack gets garbaged)  <---        <ack>
  151. <soh> 03 FC -data- xx   --->        <ack>
  152. <eot>           --->
  153. .           <---        <ack>
  154.  
  155. -------- 6. PROGRAMMING TIPS.
  156.  
  157. * The character-receive subroutine should be called with a parameter specifying
  158. the number of seconds to wait.  The receiver should first call it with a time
  159. of 10, then <nak> and try again, 10 times.
  160. . After receiving the <soh>, the receiver should call the character receive
  161. subroutine with a 1-second timeout, for the remainder of the message and the
  162. <cksum>.  Since they are sent as a continuous stream, timing out of this
  163. implies a serious like glitch that caused, say, 127 characters to be seen
  164. instead of 128.
  165.  
  166. * When the receiver wishes to <nak>, it should call a "PURGE" subroutine, to
  167. wait for the line to clear.  Recall the sender tosses any characters in its
  168. UART buffer immediately upon completing sending a block, to ensure no glitches
  169. were mis-interpreted.
  170. . The most common technique is for "PURGE" to call the character receive
  171. subroutine, specifying a 1-second timeout, and looping back to PURGE until a
  172. timeout occurs.  The <nak> is then sent, ensuring the other end will see it.
  173.  
  174. * You may wish to add code recommended by Jonh Mahr to your character receive
  175. routine - to set an error flag if the UART shows framing error, or overrun. 
  176. This will help catch a few more glitches - the most common of which is a hit in
  177. the high bits of the byte in two consecutive bytes.  The <cksum> comes out OK
  178. since counting in 1-byte produces the same result of adding 80H + 80H as with
  179. adding 00H + 00H.
  180.  
  181. == End of file ==
  182.  
  183. Type Selection or M for list, 
  184. P to set protocol, <CR> to exit: